//
//  CourseTalkingTableViewCell.m
//  TeacherNet
//
//  Created by slz on 2017/12/7.
//  Copyright © 2017年 bnsr. All rights reserved.
//

#define kGreenColor   [UIColor colorWithRGB:0x006E00]


#import "CourseTalkingTableViewCell.h"

@implementation CourseTalkingTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        NSInteger leftRightMargin = 14;
        _commentLabel = [UILabel new];
        _commentLabel.fontSize = kFont_Size_Small_Title;
        _commentLabel.textColor = kDark_TextColor_Default;
        [self.contentView addSubview:_commentLabel];
        [_commentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(leftRightMargin);
            make.top.mas_equalTo(leftRightMargin);
            make.right.lessThanOrEqualTo(self.contentView.mas_right).offset(-128);
        }];
        
        _tagTopLabel = [UILabel new];
        _tagTopLabel.text = @"置顶";
        _tagTopLabel.backgroundColor = kGreenColor;
        _tagTopLabel.textAlignment = NSTextAlignmentCenter;
        _tagTopLabel.textColor = [UIColor whiteColor];
        _tagTopLabel.fontSize = kFont_Size_Cotent_Nomal;
        [self.contentView addSubview:_tagTopLabel];
        [_tagTopLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(_commentLabel.mas_right).offset(10);
            make.centerY.mas_equalTo(_commentLabel.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(45, 20));
        }];
        
        _tagGoodLabel = [UILabel new];
        _tagGoodLabel.text = @"精华";
        _tagGoodLabel.textAlignment = NSTextAlignmentCenter;
        _tagGoodLabel.backgroundColor = [UIColor colorWithRGB:0xDA0000];
        _tagGoodLabel.textColor = [UIColor whiteColor];
        _tagGoodLabel.fontSize = kFont_Size_Cotent_Nomal;
        [self.contentView addSubview:_tagGoodLabel];
        [_tagGoodLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(_tagTopLabel.mas_right).offset(10);
            make.centerY.mas_equalTo(_commentLabel.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(45, 20));
        }];
        
        UIImageView * imageIcon = [UIImageView new];
        imageIcon.image = [UIImage imageNamed:@"home_course_cell_user"];
        [self.contentView addSubview:imageIcon];
        [imageIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(leftRightMargin);
            make.top.mas_equalTo(_commentLabel.mas_bottom).offset(15);
            make.size.mas_equalTo(CGSizeMake(10, 10));
        }];
        
        _uNmelLabel = [UILabel new];
        _uNmelLabel.textColor = kLight_TextColor_Default;
        _uNmelLabel.fontSize = kFont_Size_Cotent_Middle;
        [self.contentView addSubview:_uNmelLabel];
        [_uNmelLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(imageIcon.mas_right).offset(5);
            make.centerY.mas_equalTo(imageIcon.mas_centerY);
            make.right.lessThanOrEqualTo(self.contentView.mas_right).offset(-260);
        }];
        
        UILabel * midLabel = [UILabel new];
        midLabel.text = @"发起讨论";
        midLabel.textColor = kLight_TextColor_Default;
        midLabel.fontSize = kFont_Size_Cotent_Middle;
        [self.contentView addSubview:midLabel];
        [midLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(_uNmelLabel.mas_right).offset(5);
            make.centerY.mas_equalTo(_uNmelLabel.mas_centerY);
        }];

        _dataLabel = [UILabel new];
        _dataLabel.textColor = [UIColor colorWithRGB:0xABACAD];
        _dataLabel.fontSize = kFont_Size_Cotent_Middle;
        [self.contentView addSubview:_dataLabel];
        [_dataLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(midLabel.mas_right).offset(10);
            make.centerY.mas_equalTo(midLabel.mas_centerY);
        }];
    
        
        _lookLabel = [UILabel new];
        _lookLabel.textColor = [UIColor redColor];
        _lookLabel.fontSize = kFont_Size_Cotent_Middle;
        _lookLabel.text = @"0";
        [self.contentView addSubview:_lookLabel];
        [_lookLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.contentView.mas_right).offset(-leftRightMargin);
            make.centerY.mas_equalTo(_dataLabel.mas_centerY);
        }];
        
        UILabel * looklLabel = [UILabel new];
        looklLabel.textColor = kLight_TextColor_Default;
        looklLabel.fontSize = kFont_Size_Cotent_Middle;
        looklLabel.text = @"浏览";
        [self.contentView addSubview:looklLabel];
        [looklLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(_lookLabel.mas_left).offset(-2);
            make.centerY.mas_equalTo(_dataLabel.mas_centerY);
        }];
        
        _anserCountLable = [UILabel new];
        _anserCountLable.textColor = [UIColor redColor];
        _anserCountLable.fontSize = kFont_Size_Cotent_Middle;
        _anserCountLable.text = @"0";
        [self.contentView addSubview:_anserCountLable];
        [_anserCountLable mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(looklLabel.mas_left).offset(-10);
            make.centerY.mas_equalTo(_dataLabel.mas_centerY);
        }];
        
        
        UILabel * anserLabel = [UILabel new];
        anserLabel.textColor = kLight_TextColor_Default;
        anserLabel.fontSize = kFont_Size_Cotent_Middle;
        anserLabel.text = @"回复";
        [self.contentView addSubview:anserLabel];
        [anserLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(_anserCountLable.mas_left).offset(-2);
            make.centerY.mas_equalTo(looklLabel.mas_centerY);
        }];
        
        UIView * lineView = [UIView quickLineColorView];
        [self.contentView addSubview:lineView];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.and.bottom.mas_equalTo(self.contentView);
            make.height.mas_equalTo(.5);
        }];
    }
    return self;
}

-(void)layoutWithTalkingModel:(TTTalkingModel *)model
{
    self.commentLabel.text = model.title;
    self.tagTopLabel.hidden = !model.isTop;
    self.tagGoodLabel.hidden = !model.isGood;
    self.uNmelLabel.text = model.userName;
    self.dataLabel.text = model.time;
    self.anserCountLable.text = model.replyTimes;
    self.lookLabel.text = model.watchTimes;
}

@end
